package com.mask.im.business.service.impl;

import com.mask.im.business.model.vo.MallVO;
import com.mask.im.business.service.CommunicationService;
import com.mask.im.business.service.MailDraftService;
import com.mask.im.business.common.util.EmailUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Objects;

@Service
public class CommunicationServiceImpl implements CommunicationService {

	@Autowired
	private EmailUtil emailUtil;

	@Autowired
	private MailDraftService mailDraftService;

	@Override
	@Async
	public void sendMall(MallVO mallVO) {
		if (Objects.nonNull(mallVO.getId())){
			mailDraftService.removeById(mallVO.getId());
		}
		HashMap<String, Object> hashMap = new HashMap<>();
		hashMap.put("context",mallVO.getContext());
		emailUtil.sendSimpleMail(mallVO);
	}
}
